program highvoltage
	implicit none
	real :: x, root
! 	do x = -100, 100.0, 0.1
! 		print *,x, f(x)
! 	end do
	print *,'Enter a number to start with'; read *,x
	root = fs_newtonRhapsdon(x, 0.0001)
	print *,abs(root)
contains
	real function f(x) 
		real, intent(in)	::	x
		real				::	x1
		x1 = abs(x)
		f =2*x*x*log(x)**2 - 2*x*x*log(x) + 2*log(x)
	end function f

	real function f1(x) 
		real, intent(in)	::	x
		real				::	x1
		x1 = abs(x)
		f1=4*x*log(x)**2 - 2*x + 2/x
		if(x<0)	f1 = -1*f1
	end function f1
	
	recursive function fs_newtonRhapsdon(x1, convergence_limit) result(root)
		real, intent(in)	:: x1				!  x1 and x2 should bracket the root
	    real, intent(in)	:: convergence_limit	!  absolute limit for resolution of root eg.-use 0.00001
	    real             	:: root
	    real				:: x0
		x0=x1-f(x1)/f1(x1)
! 		if(x0 <= 0) x0 = convergence_limit
		print *,x0
! 		read *,root
		if( abs((x0-x1)/x1) < convergence_limit ) then 
			write(*,*) x0  
			root = x0 
			return
		else 
			root = fs_newtonRhapsdon(x0, convergence_limit) 
		end if 
	end function fs_newtonRhapsdon
end program